package com.aaron.kjviewutils.car;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aaron.kjviewutils.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Aaron on 2017/3/3.
 */

public class CarInfoAdapter extends RecyclerView.Adapter<CarInfoAdapter.CarInfoViewHolder> {

    private List<CarInfoBean.CarInfoInner> datas;
    private Context context;

    public CarInfoAdapter(Context context, List<CarInfoBean.CarInfoInner> datas)
    {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public CarInfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_carinfo, parent, false);
        return new CarInfoViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final CarInfoViewHolder holder, int position) {
        if(null!=datas&&!datas.isEmpty()&&null!=datas.get(position))
        {
            CarInfoBean.CarInfoInner carInfoInner = datas.get(position);
            holder.brandName.setText(carInfoInner.brandName);
            holder.seriesName.setText(carInfoInner.seriesName);
            holder.guidePrice.setText("指导价："+carInfoInner.guidePrice);
        }
    }

    @Override
    public int getItemCount() {
        return (null==datas)?0:datas.size();
    }


    public static class CarInfoViewHolder extends RecyclerView.ViewHolder
    {
        @Bind(R.id.brandName)
        TextView brandName;
        @Bind(R.id.seriesName)
        TextView seriesName;
        @Bind(R.id.guidePrice)
        TextView guidePrice;

        public CarInfoViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
